<?php

namespace app\admin\controller;

use app\common\controller\BaseController;
use think\App;
use think\db\Where;
use \Throwable;
use app\admin\model\Member as memberModel;

class Member extends BaseController
{
    protected $model;

    public function __construct(App $app, memberModel $model)
    {
        parent::__construct($app);
        $this->model = $model;
    }

    /**
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * 用户列表
     */
    public function query()
    {
        $where = new Where();
        $where['status'] = 1;
        $order = ['create_time' => 'desc'];
        $field = "member_id,nickname,gender,headimg,phone,integral,member_id task_num,create_time";
        $page = input('page/d', 1);
        $pageSize = input('page_size/d', 10);
        return $this->model->getList($where, $field, $order, $page, $pageSize);
    }

    /**
     * 显示内容
     * GET    blog/:id
     * @return array
     */
    public function detail()
    {
        try {
            return $this->model->getOne($this->params);
        } catch (Throwable $ex) {
            return $this->returnException($ex);
        }
    }

    /**
     * @return array
     * 更新地理位置
     */
    public function location()
    {
        try {
            return $this->model->updateLocation($this->params);
        } catch (\Exception $ex) {
            return $this->returnException($ex);
        }
    }

    /**
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * 订单记录
     */
    public function orderRecords()
    {
        $this->params['page'] = empty($this->params['page']) ? 1 : $this->params['page'];
        $this->params['page_size'] = empty($this->params['page_size']) ? 15 : $this->params['page_size'];
        return $this->model->orderRecords($this->params);
    }

    /**
     * @return array
     * 微信提现
     */
    public function withdraw()
    {
        try {
            return $this->model->doWithdraw($this->params);
        } catch (\Exception $ex) {
            return $this->returnException($ex);
        }
    }

    /**
     * @return array
     * 我的订单
     */
    public function order()
    {
        $page = input('page/d', 1);
        $pageSize = input('page_size/d', 15);
        $data['self_publish'] = \app\model\ReceiveOrder::where('userID', $this->params['userID'])
            ->field('title,type,orderNo,totalMoney,completeDate,status,ordertaking,ufinish,pfinish')
            ->page($page, $pageSize)
            ->select();
        $data['self_receive'] = \app\model\ReceiveOrder::where('perid', $this->params['userID'])
            ->field('title,type,orderNo,totalMoney,completeDate,status,ordertaking,ufinish,pfinish')
            ->page($page, $pageSize)
            ->select();
        return $this->returnRight($data);

    }

}
